<?php 
/**
* 
* 
*/


class MailController extends Zend_Controller_Action
{
    protected $checkZona = FALSE;
    protected $checkAcceso = FALSE;
    

    public function indexAction()
    {
        
        $this->view->headTitle('Correos Recibidos');
              
       
        $auth = Zend_Auth::getInstance();

        if($auth->getIdentity()->id){
            $id_user=$auth->getIdentity()->id;
            $usuario=$auth->getIdentity()->usuario;
        }
        

        $id_user=$auth->getIdentity()->id;

        $md5=md5($id_user.$usuario);
        
        $this->view->id_user=$id_user;
        $this->view->md5=$md5;
                        
        $m_mail=new Application_Model_Mail();
    
        $rows=  $m_mail->getMails($id_user);
        foreach($rows as &$v)
        {
            $v['url']='/mail/mail/id/'.$v['id'].'_'.md5($v['asunto']);
        }
    
        $this->view->rows = $rows;
    }
    
    
    
    
    
    public function mailAction()
    {
        $auth = Zend_Auth::getInstance();

        if($auth->getIdentity()->id){
            $id_user=$auth->getIdentity()->id;
        }else{
            $id_user=$this->_getParam('id');
        }

        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(TRUE);
        
        $id=$this->_getParam('id');
        $ruta=APPLICATION_PATH . '/mail/';
        
        $file=$ruta.$id.'.gz';
        
        $filter     = new Zend_Filter_Decompress('Gz');
        $compressed = $filter->filter($file);
        
        print $compressed;
        
        list($id_mail,$other) =explode('_',$id);
        $m_mail=new Application_Model_Mail2User();
        $m_mail->updateRow(array('leido'=>1),array('id_mail=?'=>$id_mail,'id_para=?'=>$id_user));
        
     }
    

    public function borrarAction()
    {
        
        $id=$this->_getParam('id');
        $axu= explode('_',$id);
        $id_mail=$axu[0];
        $id_para=$axu[1];
        
        $where['id_mail=?']=$id_mail;
        $where['id_para=?']=$id_para;

        
        $m_mail=new Application_Model_Mail2User();
        $m_mail->deleteRow($where);
        
        $json['status']='ok';
        $this->_helper->json($json);
         
        
    }
    
    
  
}


